from tools.listNode import listToNode, nodeToList


def mergeTwoLists(l1, l2):
    if l1 == None or l2 == None:
        return l1 or l2
    if l1.val <= l2.val:
        l1.next = mergeTwoLists(l1.next, l2)
        return l1
    else:
        l2.next = mergeTwoLists(l1, l2.next)
        return l2


l1 = listToNode([1, 2, 4])
l2 = listToNode([1, 3, 4])
print(nodeToList(mergeTwoLists(l1, l2)))  # [1,1,2,3,4,4]
